/**
 * CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

package com.cmcc.zysoft.infocollection.mobile.dao;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import com.cmcc.zysoft.infocollection.model.Message;
import com.starit.common.dao.hibernate.HibernateBaseDaoImpl;

/**
 * @author 袁凤建
 * <br />邮箱: yuan.fengjian@ustcinfo.com
 * <br />描述: MMessageDao.java
 * <br />版本: 1.0.0
 * <br />日期: 2013-8-23 上午11:12:54
 * <br />CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

@Repository
public class MMessageDao extends HibernateBaseDaoImpl<Message, String> {

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	/**
	 * 通过消息ID获取消息详细信息.
	 * @param messageId 消息ID
	 * @return Map<String, Object>
	 */
	public Map<String, Object> getMessageById(String messageId) {
		String sql = 
				" SELECT a.message_id AS messageId, a.message_title AS title, a.message_content AS content, a.add_date AS publishTime," +
				" (SELECT b.user_name FROM tb_c_system_user b WHERE a.add_man = b.user_id) AS publishMan, a.add_man as addMan" +
				" FROM tb_b_message a WHERE a.message_id = ?";
		List<Map<String, Object>> list = this.jdbcTemplate.queryForList(sql, messageId);
		if(!list.isEmpty()) {
			return list.get(0);
		} else {
			return null;
		}
	}
}